﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace vietnameseprocessing
{
    class KiemTraDLK
    {
        Dictionary<string, int> list1Word = new Dictionary<string, int>();
        Dictionary<string, int> list2Word = new Dictionary<string, int>();
        Dictionary<string, double> P_LK = new Dictionary<string, double>();

        double nguongLK = 0.002;

        public double NguongLK { get { return nguongLK; } set { nguongLK=value;} }
        public void readData(string path1W, string path2W)
        {
            StreamReader sr = new StreamReader(path1W);
            string s;
            while ((s = sr.ReadLine()) != null)
            {
                string[] kv = s.Split(':');
                list1Word[kv[0]] = Int32.Parse(kv[1]);
            }
            sr.Close();
            sr = new StreamReader(path2W);
            while ((s = sr.ReadLine()) != null)
            {
                string[] kv = s.Split(':');
                list2Word[kv[0]] = Int32.Parse(kv[1]);
            }
            sr.Close();
        }
        public void process()
        {
            foreach (KeyValuePair<string, int> item in list2Word)
            {
                string[] word = item.Key.Split(' ');
                P_LK.Add(item.Key, Math.Pow(item.Value * 1.0, 2) / (list1Word[word[0]] * list1Word[word[1]]));
            }
        }
        public void writeData(string path)
        {
            StreamWriter sw = new StreamWriter(path);
            string t = "";
            double tt = 0.0;
            foreach (KeyValuePair<string, double> pair in P_LK)
            {
                string[] tu = pair.Key.Split(' ');
                if (Utils.KiemTraTV.kiemTra(tu[0], Utils.KiemTraTV.CheDo_KiemTra.CD) && Utils.KiemTraTV.kiemTra(tu[1], Utils.KiemTraTV.CheDo_KiemTra.CD))
                {
                    tt = Math.Round(pair.Value * 1.0, 4);
                    if (tt != 0 && tt > nguongLK)
                    {
                        t = pair.Key + ":" + tt;
                        sw.Write(t + "\n");
                    }
                }
            }
            sw.Flush();
            sw.Close();
        }
    }
}
